package com.example.contentresolvermodule

import android.content.ContentUris
import android.content.Intent
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.LinearLayout
import androidx.core.content.contentValuesOf

class MainActivity : AppCompatActivity() {
    private val TAG = "MainActivity"
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }

    fun insert(view: View) {
        val parse = Uri.parse("content://com.example.contentprovidermodule.provider/myprovider")
        val contentValuesOf = contentValuesOf("name" to "jerry")

        contentResolver.insert(parse,contentValuesOf)

    }
    fun delete(view: View) {}
    fun update(view: View) {}
    fun query(view: View) {
        val parse = Uri.parse("content://com.example.contentprovidermodule.provider/myprovider")
        contentResolver.query(parse,null,null,null,null)
                ?.apply{
//                    ContentUris
                    while (moveToNext()){
                        val id = getInt(getColumnIndex("id"))
                        val name=getString(getColumnIndex("name"))
                        Log.d(TAG, "id=$id,name=$name")
                    }
                    close()
                }
    }

    fun display(view: View) {
        startActivityForResult(Intent(this,ContactListActivity::class.java),1)
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
    }
}